package wq.gdky005.custom;

import wq.gdky005.R;
import wq.gdky005.app.MainApplication;
import wq.gdky005.util.ToastUtil;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;

/**
 * 自定义一个对话框，在住Activity里面放一个测试按钮，就可以测试
 * @author wangqing
 * 2013-6-13
 */
public class MyDialog extends Dialog implements
		android.view.View.OnClickListener {
	private Context context;
	private Button camera;
	private Button album;
	private Button cancel;

	public MyDialog(Context context) {
		super(context);
		this.context = context;
//		setWindow();
	}

	public MyDialog(Context context, int theme) {
		super(context, theme);
		this.context = context;
//		setWindow();
	}

	public MyDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		this.context = context;
//		setWindow();
	}

	private void setWindow() {
		LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
		p.height = (int) (MainApplication.screenHight * 0.8); // 高度设置为屏幕的0.6
		p.width = (int) (MainApplication.screenWidth * 0.95); // 宽度设置为屏幕的0.95
//		p.x =0;//这两句设置了对话框的位置．0为中间
//      p.y =180;
        p.alpha=0.6f;//这句设置了对话框的透明度
		getWindow().setAttributes(p); // 设置生效
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_layout);
		setWindow();

		camera = (Button) findViewById(R.id.camera);
		album = (Button) findViewById(R.id.Album);
		cancel = (Button) findViewById(R.id.cancel);

		camera.setOnClickListener(this);
		album.setOnClickListener(this);
		cancel.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.camera:
			ToastUtil.showMessageText(context, "camera");
			break;
		case R.id.Album:
			ToastUtil.showMessageText(context, "Album");
			break;
		case R.id.cancel:
			ToastUtil.showMessageText(context, "cancel");
			break;

		default:
			break;
		}
	}

}
